package com.xiaomo.gitee.datamanager.security.handler;

import com.xiaomo.gitee.datamanager.common.exception.UsernameExistedException;
import com.xiaomo.gitee.datamanager.common.result.Code;
import com.xiaomo.gitee.datamanager.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

@ControllerAdvice
public class CreateAccountFailedHandler {

    @ExceptionHandler(UsernameExistedException.class)
    @ResponseBody
    public Result<?> userNameExisted(Exception e) {
        return Result.fail(Integer.parseInt(Code.USERNAME_EXISTED),Code.getInfo(Code.USERNAME_EXISTED));
    }

}
